﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class GetActivityFeedbackListAction : AuthGetAction<Params.GetActivityFeedbackListParams,
        Results.GetActivityFeedbackListResult>
    {
        protected override ActionResult<Results.GetActivityFeedbackListResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.GetActivityFeedbackListParams opParams)
        {
            ServiceResult<List<Model.Data.ActivityFeedbackView>> serviceResult = new ActivityService().GetFeedbackList(opParams.ActivityId);

            Results.GetActivityFeedbackListResult actionResult = new Results.GetActivityFeedbackListResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {

                for (int index = 0; index < serviceResult.Data.Count; index++)
                {
                    Results.GetActivityFeedbackListResult.FeedbackItem item = new Results.GetActivityFeedbackListResult.FeedbackItem();
                    item.CreatorId = serviceResult.Data[index].CreatorId;
                    item.Content = serviceResult.Data[index].Content;
                    item.CreatedTime = serviceResult.Data[index].CreatedTime;
                    item.CreatorAvatarUrl = string.Format("{0}{1}", Configs.BaseWebUrl, serviceResult.Data[index].CreatorAvatarUrl);
                    item.CreatorNickName = serviceResult.Data[index].CreatorNickName;

                    actionResult.Add(item);
                }

                return new ActionResult<Results.GetActivityFeedbackListResult>("1.0.1", true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.GetActivityFeedbackListResult>("1.0.1", false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
